package com.se.back.controller;

import com.se.back.entity.Business;
import com.se.back.entity.Customer;
import com.se.back.entity.Login;
import com.se.back.entity.User;
import com.se.back.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {
    @Autowired
    private LoginService loginService;

    @PostMapping("/login")
    public ResponseEntity<Object> login(@RequestBody Login login) {
        String id = login.getId();
        String password = login.getPassword();
        User user = loginService.userLogin(id, password);

        if (user != null) {
            // 登录成功，返回用户信息
            return ResponseEntity.ok(user);
        } else {
            // 登录失败，返回错误信息
            String errorMessage = "用户名或密码错误";
            return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(errorMessage);
        }
    }

}
